package com.lxw.study.behavioral.iterator;

import java.util.Iterator;

public class MyArrayList implements Iterable {
    private int index;
    private Object[] elementData = new Object[8];


    @Override
    public Iterator iterator() {
        return new MyIterator();
    }

    private class MyIterator implements Iterator {
        int cursor;

        @Override
        public boolean hasNext() {
            return cursor != index;
        }

        @Override
        public Object next() {
            Object elementDatum = elementData[cursor];
            cursor++;
            return elementDatum;
        }
    }

    public void add(Object o) {
        elementData[index] = o;
        index++;

    }
}
